#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

#define REP(i, x, y) for (auto i = (x), _##i = (y); i < _##i; ++i)
#define PER(i, x, y) for (auto i = (x), _##i = (y); i > _##i; --i)

template<class T=int>
inline void OO(const T &coll, const char *del = ",") {
    copy(coll.begin(), coll.end(), ostream_iterator<decltype(*coll.begin())>(cerr, del));
    cerr << endl;
}

const int n = 8;
vector<int> a(n, 0);
vector<bool> book(n, false);

bool judge(vector<int> &v) {
    for (int i = 0; i < v.size(); i++)
        for (int j = i + 1; j < v.size(); j++) {
            if (abs(v[i] - v[j]) == j - i)return false;
        }
    return true;
}

void dfs(int k) {
    if (k >= n) {
        if (!judge(a))return;
        copy(a.begin(), a.end(), ostream_iterator<int>(cout, ""));
        cout << endl;
        return;
    }
    for (int i = 0; i < n; i++) {
        if (book[i])continue;
        book[i] = true;
        a[k] = i;
        dfs(k + 1);
        book[i] = false;

    }

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    dfs(0);
    return 0;
}
